<?php
/**
 * Author: 式神(vashi)
 * email: 289650682@qq.com
 * Date: 2019/3/7 16:43
 * FileName: TagsArticle.php
 */

namespace app\cms\model;

class PostArticle extends Common
{
    protected $tip_name = '推荐文章';
    protected $validate;
    protected $table;

    public function initialize()
    {
        parent::initialize();
        $this->validate = new \app\cms\validate\PostArticle();
    }

    //添加内容
    public function add($input){
        if(count($input["post_id"])>0){
			$arr=[];
			foreach($input["post_id"] as $v){
				$n=[
					"article_id" => $input['id'],
					"post_id" => $v,
					"create_time" => time(),
					"update_time" => time()
				];
				array_push($arr,$n);
			}
			$this->saveAll($arr);
		}

		$this->res['code']=0;
		$this->res['msg']=$this->tip_name.'成功！';
		return $this->res;
    }

    //编辑内容
    public function edit($input){
		$this->where('article_id',$input['id'])->delete();
		if(count($input["post_id"])>0){
			$arr=[];
			foreach($input["post_id"] as $v){
				$n=[
					"article_id" => $input['id'],
					"post_id" => $v,
					"create_time" => time(),
					"update_time" => time()
				];
				array_push($arr,$n);
			}
			$this->saveAll($arr);
		}

		$this->res['code']=0;
		$this->res['msg']=$this->tip_name.'成功！';
		return $this->res;
    }

    //编辑内容
    public function editSort($input){
        return $this->editModel($input);
    }

    public function del($input){
        $res = $this->delModel($input);
        return $res;
    }
}